package com.lgy.ms.core.exception;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Gylin
 */
public class BusinessException extends RuntimeException {

    private String errorCode;
    private String errorMsg;
    /**
     * 异常返回时可能需要多带的额外信息
     */
    private Map<String, Object> otherInfo;

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public BusinessException(String message) {
        super(message);
        this.errorMsg = message;
    }

    public BusinessException(String errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
        this.errorMsg = message;
    }

    public BusinessException(String errorCode, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    public BusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public Map<String, Object> getOtherInfo() {
        return otherInfo;
    }

    public void setOtherInfo(Map<String, Object> otherInfo) {
        this.otherInfo = otherInfo;
    }

    public void addOtherInfo(String key, Object value) {
        if (this.otherInfo == null) {
            this.otherInfo = new HashMap<>();
        }
        otherInfo.put(key, value);
    }

    public void addOtheInfos(Map<String, Object> infos) {
        if (this.otherInfo == null) {
            this.otherInfo = new HashMap<>();
        }
        otherInfo.putAll(infos);
    }
}
